package com.woniuxy.utils;

import org.springframework.http.HttpStatus;

/**
 * 给前端返回信息的工具类
 */
public class ResultVO {

    private Integer code;
    private String msg;
    private Object data;

    public static ResultVO success() {
        return success("操作成功");
    }

    public static ResultVO success(String msg) {
        return success(HttpStatus.OK.value(), msg);
    }

    public static ResultVO success(Integer code, String msg) {
        return success(code, msg, null);
    }

    public static ResultVO success(String msg, Object data) {
        return success(200, msg, data);
    }

    public static ResultVO success(Integer code, String msg, Object data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setData(data);
        return resultVO;
    }

    public static ResultVO fail() {
        return fail("操作失败");
    }

    public static ResultVO fail(String msg) {
        return fail(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }

    public static ResultVO fail(Integer code, String msg) {
        return fail(code, msg, null);
    }

    public static ResultVO fail(Integer code, String msg, Object data) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setData(data);
        return resultVO;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
